package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author jyh
 * @Description: 营销规则枚举类
 */
@Getter
public enum MarketingManagementSettingEnum {
    /**
     * 优惠券使用规则 默认关闭 本规则的status没有意义，需要看具体的每一项开关
     */
    COUPON_USAGE_SETTING(1, "enum.marketingManagementRule.name.coupon_usage_setting", "rule1", "enum.marketingManagementRule.tip.coupon_usage_setting", 0),
    /**
     * 营销计算规则设置 默认开启
     */
    MARKETING_CALCULATION_RULE_SETTING(2, "enum.marketingManagementRule.name.marketing_calculation_rule_setting", "rule2", "enum.marketingManagementRule.tip.marketing_calculation_rule_setting", 1),

    /**
     * 未知规则,当异常时用于返回
     */
    UNKNOWN(404, "enum.marketingManagementRule.name.unknown", "unknown", "", 0);


    /**
     * 枚举值 --
     */
    private final int code;

    /**
     * 枚举信息--中文名称
     */
    private final String name;

    /**
     * 枚举描述 --英文名称
     */
    private final String alias;

    /**
     * 枚举描述 --提示
     */
    private final String tip;
    /**
     * 默认状态
     */
    private final int status;

    /**
     * 构造一个<code>SubModuleEnum</code>枚举对象
     *
     * @param code  枚举值
     * @param name  枚举名
     * @param alias 别名
     */
    MarketingManagementSettingEnum(int code, String name, String alias, String tip, Integer status) {
        this.code = code;
        this.name = name;
        this.alias = alias;
        this.tip = tip;
        this.status = status;
    }

    /**
     * 通过枚举<code>alias</code>获得枚举
     *
     * @param alias 别名
     * @return PublicCustomerRuleEnum
     */
    public static MarketingManagementSettingEnum getByAlias(String alias) {
        for (MarketingManagementSettingEnum cacheCode : values()) {
            if (cacheCode.getAlias().equals(alias)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     * @return PublicCustomerRuleEnum
     */
    public static MarketingManagementSettingEnum getByCode(Integer code) {
        for (MarketingManagementSettingEnum cacheCode : values()) {
            if (code.equals(cacheCode.getCode())) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    /**
     * 获取全部枚举
     *
     * @return List<PublicCustomerRuleEnum>
     */
    public static List<MarketingManagementSettingEnum> getAllEnum() {
        List<MarketingManagementSettingEnum> list = new ArrayList<>();
        for (MarketingManagementSettingEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    /**
     * 获取全部枚举值
     *
     * @return List<String>
     */
    public List<String> getAllEnumAlis() {
        List<String> list = new ArrayList<>();
        for (MarketingManagementSettingEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache.getAlias());
        }
        return list;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

    public String getTip() {
        return I18nMessageUtil.getMessage(tip);
    }

}
